﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="APList.aspx.cs" Inherits="Zyg.SSO.Web.APList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>应用列表</title>
    <link href="style/screen.css" rel="Stylesheet" type="text/css" />
    <link href="style/applist.css" rel="stylesheet" type="text/css" />
    <link href="style/jqueryui/smoothness/ui.all.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .ui-dialog-overlay
        {
            background-color: #c1c1c1;
            opacity: 0.3;
            filter: alpha(opacity = 40);
        }
    </style>
</head>
<body class="dbody">
    <form id="form1" runat="server">
    <div class="clearfix" id="myApps">
        <% 
            if (applist.Count > 0)
            {
                for (i = 0; i < applist.Count; i++)
                {
                    applist[i].PictureAddress = ResolveUrl(applist[i].PictureAddress);
        %>
        <div class="appBox" id='<%=applist[i].Id %>'>
            <div class="appImage">
                <a href="javascript:;" style="cursor: pointer">
                    <img src="<%=applist[i].PictureAddress %>" alt='查看<%=applist[i].Name%> ' title='查看<%=applist[i].Name%> '
                        width="48" height="48" />
                </a>
            </div>
            <div class="appTitle">
                <a href="javascript:'" title='<%=applist[i].Name%>' style="cursor: pointer">
                    <%=applist[i].Name%>
                </a>
            </div>
        </div>
        <%}
            }
            else
            {%>
        暂无任何应用
        <%} %>
    </div>
    <% if (otherAppList.Count > 0)
       { 
    %>
    <div class="clearfix" style="margin-top: 10px; font-size: 12px;">
        <fieldset>
            <legend>您也可以添加如下应用</legend>
            <% 
                for (int i = 0; i < otherAppList.Count; i++)
                {
            %>
            <div class="appBox">
                <div class="appImage">
                    <a href='AddAccountApp.aspx?appId=<%= otherAppList[i].Id.ToString() %>' style="cursor: pointer">
                        <img src="<%=otherAppList[i].PictureAddress %>" alt='开通<%=otherAppList[i].Name%> '
                            title='开通<%=otherAppList[i].Name%> ' width="48" height="48" />
                    </a>
                </div>
                <div class="appTitle">
                    <a id="A1" href='AddAccountApp.aspx?appId=<%= otherAppList[i].Id.ToString() %>' title='<%=otherAppList[i].Name%>'
                        style="cursor: pointer">
                        <%=otherAppList[i].Name%>
                    </a>
                </div>
            </div>
            <%} %>
        </fieldset>
    </div>
    <%} %>
    <div id="editTool">
        <a href="">维护用户映射</a>
    </div>
    <br />
    <div id="ChooseNameBox" style="padding: 0px;">
        <div id="ChooseName" style="margin: 10px;">
        </div>
    </div>
    <div style="height: 200px;">
    </div>
    </form>

    <script type="text/javascript" src="/script/jquery/jquery-1.2.6.min.js"></script>

    <script type="text/javascript" src="/script/jquery/jquery-ui-1.6.custom.min.js"></script>

    <script type="text/javascript" src="/script/zyg.sso.js"></script>

    <script type="text/javascript">
        $(".appBox", "#myApps").each(
            function() {
                $(this).hover(
                    function() {
                        var id = $(this).attr("id");
                        var offset = $(this).offset();

                        var tool = $("#editTool");
                        var link = tool.find("a");

                        tool.css({ left: offset.left + 2 + "px",
                            top: offset.top + 2 + "px",
                            display: "block",
                            opacity: 0.7
                        });

                        link.attr("href", "/MaintanceAccountAppUsers.aspx?APID=" + id);
                    },
                    function() {
                        /* var tool = $("#editTool");
                        tool.css("display", "none");*/
                    }
                );
            }
        );

            $(".appBox", "#myApps").each(function() {
                var id = $(this).attr("id");
                $("#ChooseNameBox").dialog({
                    width: 400,
                    modal: true,
                    autoOpen: false,
                    draggable: true,
                    resizable: false,
                    title: '选择用户登录'
                });
                $(this).find("a").click(function() {
                    $("#ChooseName").html("<img src='images/loading.gif' width='16' alt='' />加载中...");
                    $("#ChooseNameBox").dialog("open");
                    /*$.get(
                    'ProcessLogin.ashx',
                    { appId: id },
                    function(data) {
                    if (data.success) {
                    $("#ChooseName").html(data.html);
                    } else {
                    $("#ChooseName").html(data.html);
                    }
                    },
                    "json"
                    );*/
                    $.get(
                    'ProcessLogin.ashx',
                    { appId: id },
                    function(data) {
                        if (data.success) {
                            if (data.users.length == 1) {
                                $("#ChooseNameBox").dialog("close");
                                var url = 'PassLogin.aspx?APID=' + id + '&id=' + data.users[0].id;
                                var w = window.open(url);
                                w.focus();
                            } else if (data.users.length > 0) {
                                var html = "<table id='userNames' cellpadding='0' cellspacing='0' border='0' class='infoTable' width='98%' align='center'><tr><th>编号</th><th>用户名</th><th></th></tr>";
                                for (var i = 0; i < data.users.length; i++) {
                                    html += "<tr><td>" + (i + 1) + "</td><td>" + decodeURI(data.users[i].name) + "</td><td><a href='PassLogin.aspx?APID=" + id + "&id=" + data.users[i].id + "' target='_blank'>登录</a></td></tr>";
                                }
                                html += "</table><br />";

                                $("#ChooseName").html(html);
                            } else {
                                var html = "<table id='userNames' cellpadding='0' cellspacing='0' border='0' class='infoTable' width='98%' align='center'><tr><th>编号</th><th>用户名</th><th></th></tr>";
                                html += "<tr><td colspan='3'>暂未设定用户,请先做用户映射</td></tr>";
                                html += "</table><br />";

                                $("#ChooseName").html(html);
                            }
                        } else {
                            $("#ChooseName").html(data.html);
                        }
                    },
                    "json"
                );
                });
            });

        $("body").bind("click", function() {
            var tool = $("#editTool").css("display", "none");
        });

        zyg.iframe.autoFitHeight('#ChooseNameFrame');
    </script>

</body>
</html>
